package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.model.vo.DeviceBrandAddVO;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.service.DeviceBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/4/28 17:56
 * @description : 设备品牌
 */
@RestController
@RequestMapping("/v1/deviceBrand")
@Api(value = "设备品牌")
@Validated
@Slf4j
@AuthRequired
public class DeviceBrandController {
    @Autowired
    private DeviceBrandService deviceBrandService;

    @ApiOperation(value = "添加设备品牌")
    @PostMapping("/add")
    public BaseResult addDeviceBrand(@RequestBody @Valid DeviceBrandAddVO deviceBrandAddVO){
        deviceBrandService.addDeviceBrand(deviceBrandAddVO);
        return BaseResultFactory.produceSuccess();
    }

    @ApiOperation(value = "查询设备品牌列表")
    @GetMapping("/list")
    public BaseResult queryDeviceBrandList(Pageable pageable,@ApiParam(value = "关键字") String keyword
                                                            ,@ApiParam(value = "商家id") String userId){
        return BaseResultFactory.produceSuccess(deviceBrandService.queryDeviceBrandList(pageable,keyword,userId));
    }

    @ApiOperation(value = "设备编辑获取设备品牌列表)")
    @GetMapping("/deviceEdit/list")
    public BaseResult queryDeviceBrandListForDeviceEdit(){
        return BaseResultFactory.produceSuccess(deviceBrandService.getBrandList4DeviceEdit());
    }

    @ApiOperation(value = "查询设备品牌详情")
    @GetMapping("/detail/{deviceBrandId}")
    public BaseResult queryDeviceBrandList(@PathVariable String deviceBrandId){
        return BaseResultFactory.produceSuccess(deviceBrandService.queryDeviceBrandDetail(deviceBrandId));
    }

    @ApiOperation(value = "删除设备品牌")
    @PostMapping("/delete/{deviceBrandId}")
    public BaseResult deleteDeviceBrand(@PathVariable String deviceBrandId){
        deviceBrandService.deleteDeviceBrand(deviceBrandId);
        return BaseResultFactory.produceSuccess();
    }


}
